﻿using AbpApplication.InPut;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using NewWms.Apiservice;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NewWms.ViewModels.DialogsModel
{
    public partial class UpdateBoxDialogModel : BindableBase, IDialogAware
    {


        private readonly IBaseService baseService;
        public UpdateBoxDialogModel()
        {
            InPut_BaseService2 = new InPut_BaseService2();
            baseService = new BaseService();
        }
        private string boxCode;
        public string BoxCode
        {
            get { return boxCode; }
            set { boxCode = value;RaisePropertyChanged(); }
        }

        private InPut_BaseService2 inPut_BaseService2;
        public InPut_BaseService2 InPut_BaseService2
        {
            get { return inPut_BaseService2; }
            set { inPut_BaseService2 = value; RaisePropertyChanged(); }
        }


        private async void UpdateBox()
        {

        bool res=  await  baseService.Update_Box(InPut_BaseService2);
            if (res)
            {
                await baseService.CreateLog("修改", $"修改了箱格-{InPut_BaseService2.BoxGridQuantity}格", null, null, null, null, null, null, InPut_BaseService2.BoxCode, null);
                RequestClose?.Invoke(null);
            }

        }
        [RelayCommand]
        public async void Method(string obj)
        {
            switch (obj)
            {
                case "CloseDialog": RequestClose?.Invoke(null); break;
                case "UpdateBox": UpdateBox(); break;
            }
        }   





        public string Title { get; set; } = "修改格口";
        public event Action<IDialogResult> RequestClose;
        public bool CanCloseDialog()
        {
            return true;
        }
        public void OnDialogClosed()
        {
            
        }
        public void OnDialogOpened(IDialogParameters parameters)
        {

            InPut_BaseService2.BoxCode = (string)parameters.GetValue<object>(1.ToString()); // 根据你的数据类型替换 'int'
            

        }
    }
}
